package com.ruoyi.produce.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;

import com.ruoyi.produce.domain.TraceTask;
import com.ruoyi.produce.service.ProductService;

import com.ruoyi.system.api.domain.TraceTransport;
import com.ruoyi.system.api.domain.vo.CropsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author PC
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     * 任务添加
     * @param traceTask
     * @return
     */

    @PostMapping("/addTask")
    public AjaxResult addTask(@RequestBody TraceTask traceTask){
        return AjaxResult.success(productService.addTask(traceTask));
    }


    /**
     * 根据cropsId查询任务详情
     * @param cropsId
     * @return
     */
    @GetMapping("/queryTaskByCropsId/{cropsId}")
    public AjaxResult queryTaskByCropsId(@PathVariable("cropsId") String cropsId){
        return AjaxResult.success(productService.queryTaskByCropsId(cropsId));
    }


    /**
     * 产品记录列表
     * @return
     */
    @GetMapping("/queryTaskList")
    public AjaxResult queryTaskList(){
        return AjaxResult.success(productService.queryTaskList());
    }


    /**
     * 产品加工列表
     * @param deptId
     * @return
     */
    @GetMapping("/queryCropsList/{deptId}")
    public AjaxResult queryCropsList(@PathVariable Integer deptId){
        return AjaxResult.success(productService.queryCropsList(deptId));
    }


    /**
     * 更新状态
     * @param cropsVo
     * @return
     */
    @PostMapping("/updateMachingStatus")
    public AjaxResult updateMachingStatus(@RequestBody CropsVo cropsVo){
        return AjaxResult.success(productService.updateMachingStatus(cropsVo));
    }


    /**
     * 根据农作物id更新产品状态
     * @param cropsId
     * @return
     */

    @GetMapping("/updateProductWriteStatus/{cropsId}")
    public AjaxResult updateProductWriteStatus(@PathVariable("cropsId") String cropsId){
        return AjaxResult.success(productService.updateProductWriteStatus(cropsId));
    }

    /**
     * 产品出库
     * @param cropsId
     * @return
     */
    @GetMapping("/productOutFactory/{cropsId}")
    public AjaxResult productOutFactory(@PathVariable("cropsId") String cropsId){
        return AjaxResult.success(productService.productOutFactory(cropsId));
    }




}
